﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BFlatCompile.Project
{
	internal  class JsonObject
	{
		public Dictionary<string, object> Values { get; private set; }
		public JsonObject()
		{
			this.Values = new Dictionary<string, object>();
		}

		public void AddValue(string key, object value)
		{
			if (this.Values.ContainsKey(key))
			{
				throw new Exception("Duplicate value");
			}
			this.Values.Add(key, value);
		}

		public JsonList TryGetList(string key)
		{
			if (!this.Values.ContainsKey(key))
			{
				return null;
			}

			return this.Values[key] as JsonList;
		}

		public string TryGetString(string key)
		{
			if (!this.Values.ContainsKey(key))
			{
				return null;
			}

			object output = this.Values[key];
			if (output == null) return "";
			return output.ToString();
		}
	}
}
